//
//  LXClientDetailViewController.m
//  跑跑快销
//
//  Created by linxian on 14-4-29.
//  Copyright (c) 2014年 ylife. All rights reserved.
//
#define ViewHeight                      [UIScreen mainScreen].bounds.size.height
#define navY                            ISDEVICE7 ? 20 : 0
#import "LXClientDetailViewController.h"

@interface LXClientDetailViewController ()

@end

@implementation LXClientDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    LXClientDetailView *clientDetailView = [[LXClientDetailView alloc] init];
    self.view = clientDetailView;
    _clientDetailView = clientDetailView;
    
    self.navigationController.navigationBar.translucent = NO;
    [self initActions];
    
}
#pragma mark - 初始化各种点击事件

- (void)initActions
{
    [self addBarButtons];
    [self initTableView];
    [self initFunctionBtn];
    [self initButtonAction];
    
}

#pragma mark - 初始化asTableView

- (void)initTableView
{
    _clientDetailView.cdTableView.dataSource = self;
    _clientDetailView.cdTableView.delegate = self;
    
    _clientDetailView.clientName.text = @"优生活";
}

#pragma mark - 创建navigationbar上的Item

- (void)addBarButtons
{
    // “详情”按钮
    UIBarButtonItem *detailBtn = [[UIBarButtonItem alloc] initWithTitle:@"详情    " style:UIBarButtonItemStyleDone target:self action:@selector(clickDetailBtn)];
    [self.navigationItem setRightBarButtonItem:detailBtn];
    
}

- (void)initButtonAction
{
    [_clientDetailView.LeftBtn addTarget:self action:@selector(clickLeftBtn) forControlEvents:UIControlEventTouchUpInside];
    [_clientDetailView.RightBtn addTarget:self action:@selector(clickRightBtn) forControlEvents:UIControlEventTouchUpInside];
    for (int i=0; i<NumOfButtons; i++) {
       UIButton *btn = (UIButton *)[_clientDetailView.funcView viewWithTag:i+1];
        [btn addTarget:self action:@selector(clickFuncBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    
}

- (void) initFunctionBtn
{
    _functionArray = [NSArray arrayWithObjects:@"下单",@"货架成列",@"客户卡",@"签到",@"规格表",@"查看订单",@"退货", nil];
    for (int i=0; i<NumOfButtons; i++) {
        TNButton *btn = (TNButton *)[_clientDetailView.funcView viewWithTag:i+1];
        [btn setImage:[UIImage imageNamed:@"a.png"] forState:UIControlStateNormal];
        [btn setTitle:[NSString stringWithFormat:@"%@",_functionArray[i]] forState:UIControlStateNormal];
        [btn.titleLabel setTextAlignment:NSTextAlignmentCenter];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:11]];
   }
}
- (void)clickFuncBtn:(UIButton *)sender
{
    switch (sender.tag) {
        case 1:
        {
            NSLog(@"%@",sender.titleLabel.text);
            // 下单
            LXSignInViewController * siVC = [[LXSignInViewController alloc] init];
            [self.navigationController pushViewController:siVC animated:YES];
        }
            break;
        case 2:
        {
            NSLog(@"%@",sender.titleLabel.text);
            // 货架陈列
            YXPhotoListViewController *plVC = [[YXPhotoListViewController alloc] init];
            [self.navigationController pushViewController:plVC animated:YES];
        }
            break;
        case 3:
        {
            NSLog(@"%@",sender.titleLabel.text);
            // 客户卡
        }
            break;
        case 4:
        {
            NSLog(@"%@",sender.titleLabel.text);
            // 实时签到
            YXSignInViewController *ysiVC = [[YXSignInViewController alloc] init];
            [self.navigationController pushViewController:ysiVC animated:YES];
        }
            break;
        case 5:
        {
            NSLog(@"%@",sender.titleLabel.text);
            // 规格表
            LXOrderSelfViewController *osVC = [[LXOrderSelfViewController alloc] init];
            [self.navigationController pushViewController:osVC animated:YES];
        }
            break;
        case 6:
        {
            NSLog(@"%@",sender.titleLabel.text);
            // 查看订单
        }
            break;
        case 7:
        {
            NSLog(@"%@",sender.titleLabel.text);
            // 退货
        }
            break;
        default:
            NSLog(@"超出设定按钮个数");
            break;
    }
}

- (void)clickLeftBtn
{
    NSLog(@"修复位置");
}

- (void)clickRightBtn
{
    NSLog(@"删除网点");
}



- (void)clickDetailBtn
{
    
    if (!_isShowing) {
        // 详细界面已经展开
        CATransition *animation = [CATransition animation];
        animation.type = kCATransitionFromBottom;
        animation.duration = 0.2;
        [_clientDetailView.funcView.layer addAnimation:animation forKey:nil];
        _clientDetailView.funcView.frame = CGRectMake(0, 0, 320,ViewHeight - (navY));
        
    } else {
        // 详细界面已经收起
        CATransition *animation = [CATransition animation];
        animation.type = kCATransitionFromTop;
        animation.duration = 0.4;
        [_clientDetailView.funcView.layer addAnimation:animation forKey:nil];
        _clientDetailView.funcView.frame = CGRectMake(0, buttonH * 6 + titleH, 320, 480);
    }
    _isShowing = !_isShowing;
}


#pragma mark - tableView的代理方法

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40.0f;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    // 标题
    cell.textLabel.text = @"便利店";
    
    //图片
    cell.imageView.frame = CGRectMake(0, 0, 40, 40);
    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    cell.imageView.image = [UIImage imageNamed:@"a.png"];

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [_clientDetailView.cdTableView deselectRowAtIndexPath:indexPath animated:YES];
    
}





- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
